import { ResponseBody } from "~@/utils/request"
const requestPrefix = 'user/';
const requestPrefixAuth = 'auth/';

interface UserBasicModel {
    id?: string
    username: string,
    name: string,
    phone: string,
    avatar: string
}
interface PasswordModle {
    newPwd:string
    oldPwd: string
    rePwd: string
}
interface EmailModle {
    email:string
    code: string
}
interface authorizeList {
    registeredClientId: string
    registeredClientName:string
    authorities:string
}
type userBasicSaveParams = Partial<Omit<UserBasicModel, 'id'>>
type userPasswordSaveParams = Partial<Omit<PasswordModle, 'newPwd'>>
type bindEmailParams = Partial<Omit<EmailModle, 'id'>>

export async function getUserBasicInfoApi() {
    return useGet(requestPrefix + 'user/current')
}
export async function UpdateUserBasicInfoApi(params: userBasicSaveParams):Promise<ResponseBody<UserBasicModel>> {
    return usePut(requestPrefix + 'user/perfect', params);
}

export async function getUserSecurityInfoApi() {
    return useGet(requestPrefix + 'user/security')
}
// 修改密码
export async function UpdateUserPassWordApi(params: userPasswordSaveParams):Promise<ResponseBody<PasswordModle>> {
    return usePut(requestPrefix + 'user/password/change', params);
}
export async function getEmailCode(params: string) {
    return usePost(requestPrefix + 'user/email/code?email=' + params);
}
// 修改密码
export async function bindEmailApi(params: bindEmailParams):Promise<ResponseBody<EmailModle>> {
    return usePut(requestPrefix + 'user/email/bind?email='+ params.email+'&code='+params.code);
}

export async function getListApi() {
    return useGet(requestPrefixAuth + 'registerClient/user/consent/1/10')
}
export async function deleteApi(id: string | number) {
    return useDelete(requestPrefixAuth + `registerClient/user/consent?${id}`)
}

export type{
    userBasicSaveParams,
    UserBasicModel,
    userPasswordSaveParams,
    PasswordModle,
    bindEmailParams,
    EmailModle,
    authorizeList
}